﻿#region << 版 本 注 释 >>
/*----------------------------------------------------------------
 * 版权所有 (c) 2022 北京超维景生物科技有限公司 保留所有权利。
 * CLR版本：4.0.30319.42000
 * 文件名：Kernel
 * 
 * 创建者：huangyang
 * 电子邮箱：huangyang@tvscope.cn
 * 创建时间：2023/2/9 10:12:53
 * 版本：V1.0.0
 * 描述：
 *
 * ----------------------------------------------------------------
 * 修改人：
 * 时间：
 * 修改说明：
 *
 * 版本：V1.0.1
 *----------------------------------------------------------------*/
#endregion << 版 本 注 释 >>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ImageK.Macros;

namespace ImageK.Gui
{
    /**
     * This is the progress bar that is displayed in the lower right hand corner of
     * the ImageJ window. Use one of the static IJ.showProgress() methods to display
     * and update the progress bar.
     */
    public class ProgressBar:ToolStripProgressBar
    {
        public ProgressBar()
        {
            this.Maximum = 100;
            this.Minimum = 0;
        }

        /**
         * Updates the progress bar, where abs(progress) should run from 0 to 1.
         * If abs(<code>progress</code>) == 1 the bar is erased. The bar is updated only
         * if more than 90 ms have passed since the last call. Does nothing if the
         * ImageJ window is not present.
         * @param progress Length of the progress bar to display (0...1). 
         * Using <code>progress</code> with negative sign (0 .. -1) will regard subsequent calls with
         * positive argument as sub-ordinate processes that are displayed as moving dot.
         */
        public void show(double progress)
        {
            show(progress, false);
        }

        /**
 * Updates the progress bar, where abs(progress) should run from 0 to 1.
 * @param progress Length of the progress bar to display (0...1). 
 * @param showInBatchMode show progress bar in batch mode macros?
 */
        public void show(double progress, bool showInBatchMode)
        {
            bool finished = false;
            if (progress <= -1)
                finished = true;
            if (progress >= 1)
                finished = true;
            if (finished)
            {
                this.Value = 0;
            }
            else
            {
                this.Value = (int)(progress * 100);
            }
            
            // bool finished = false;
            // if (progress <= -1)
            //     finished = true;
            // if (!dualDisplay && progress >= 1)
            //     finished = true;
            // if (!finished)
            // {
            //     if (progress < 0)
            //     {
            //         slowX = -progress;
            //         fastX = 0.0;
            //         dualDisplay = true;
            //     }
            //     else if (dualDisplay)
            //         fastX = progress;
            //     if (!dualDisplay)
            //         slowX = progress;
            // }
            // if (!showInBatchMode && (batchMode || Interpreter.isBatchMode()))
            //     return;
            // if (finished)
            // {//clear the progress bar
            //     slowX = 0.0;
            //     fastX = 0.0;
            //     showBar = false;
            //     dualDisplay = false;
            //     repaint();
            //     return;
            // }
            // long time = System.currentTimeMillis();
            // if (time - lastTime < 90 && progress != 1.0)
            //     return;
            // lastTime = time;
            // showBar = true;
            // repaint();
        }
    }
}
